#ifndef IND_SHIMMING_H
#define IND_SHIMMING_H

#include <QWidget>
#include <QPainter>
#include <QLabel>

#define REGULAR_DEFAULT_WIDTH 160
#define NONE_REGULAR_WIDTH 200
#define NONE_REGULAR_HEIGHT 140
#define DEFAULT_NO_REGULAR_RATIO 0.7
#define COG_DIAMETER_RADIUS 8
#define RETANGULAR_WIDTH 80
#define RETANGULAR_HEIGHT 50
#define TEXT_WIDTH 30

#define MAX_CELL_COUNTS 8

class IndShimmingItem;
class IndShimming : public QWidget
{
    Q_OBJECT
public:
    enum LineStyle {
        NORMAL = 0,
        DASH,
        HIDE,
    };
    enum LoadType {
        RATIO = 0,
        COUNT,
        NONE,
    };
    enum PolygonType {
        REGULAR,
        NONE_REGULAR,
    };

    explicit IndShimming(QWidget* parent = nullptr);
    void SetShowHollowPoint(bool flag);
    void SetShowCOG(bool flag);
    void SetCOGLocation(double x, double y);
    void SetNodesNumber(const std::vector<char>& nodes);
    void SetCellCounts(const std::vector<int>& counts);
    void SetLineStyle(LineStyle style);
    void SetWidthHeightRatio(double ratio);
    void SetPolygonType(PolygonType type);
    void SetAmplificationFactor(double factor);
    void ShowBlueTriangle(int nodeNumber);
    void ClearBlueTriangle(int nodeNumber);
    void SetHighlight(int nodeNumber);
    void ClearHighLight(int nodeNumber);
    void SetLoadType(LoadType type);
protected:
    void paintEvent(QPaintEvent* event) override;
private:
    bool m_showHollowPoint { true };
    bool m_showCOG { true };
    double m_COG_x { 0 };
    double m_COG_y { 0 };
    QLabel* m_cog { nullptr };
    std::vector<char> m_nodeNumber;
    std::vector<int> m_cellCounts;
    LineStyle m_lineStyle { LineStyle::NORMAL };
    double m_widthHeightRatio { 1.0 };
    int m_polygonWidth { REGULAR_DEFAULT_WIDTH };
    int m_polygonHeight { REGULAR_DEFAULT_WIDTH };
    double m_amplificationFactor { 1.0 };
    PolygonType m_polygonType { PolygonType::REGULAR };
    std::map<char, IndShimmingItem*> m_items;
    QLabel* m_HR { nullptr };
    LoadType m_loadType { LoadType::RATIO };

    void DrawHollowPoint(QPainter& painter);
    void DrawCOG(QPainter& painter);
    void DrawNodes(QPainter& painter);
    void DrawThreeNodes(QPainter& painter);
    void DrawFourNodes(QPainter& painter);
    void DrawLine(QPainter& painter, const QPointF& start, const QPointF& end);
    void DrawHR();
    void DrawTail(QPainter& painter);
signals:
};

#endif // IND_SHIMMING_H
